Mathematics of musical scales